<?php
/**
 * 单个视频转码
 */
require_once dirname(dirname(__DIR__))."/common.php";
use app\cls\tom\Response;
use app\cls\tom\SysResource;
use app\model\UserVideo;
use app\cls\tom\FFmpeg;
$ffmpeg = new FFmpeg();

$video_url=$_REQUEST['video_url'];
if(empty($video_url)){
    Response::output(-1,"缺少参数");
}
//先去获取视频的宽高
$arr=[];
$wh=$ffmpeg->getVideoDetail($video_url,1);
$width=$wh['width'];
$height=$wh['height'];
$arr['width']=$width;
$arr['height']=$height;
//这是要转码变成的宽高
$new_width="480";
$new_height="270";
//判断是否要加黑边
if($new_width > $width){
    $arr['add_width']=($new_width-$width)/2;
}else{
    $arr['add_width']=0;
}
if($new_height > $height){
    $arr['add_height']=($new_height-$height)/2;
}else{
    $arr['add_height']=0;
}
//进行9:16的视频转码
$video_path = CDN_PATH."/tmp1/".pathinfo($video_url,PATHINFO_BASENAME);
$res=$ffmpeg->transCode1($video_url,$video_path,$arr);
//var_dump($res);exit;
if($res){
    $video=str_replace(CDN_PATH,CDN_HOST,$video_path);
    Response::output(0,"转码成功",$video);
}else{
    Response::output(-1,"转码失败");
}



